package com.yugao.fintech.antelope.pay.common.model.mq;

import com.alibaba.fastjson2.JSON;
import com.yugao.fintech.antelope.base.model.module.mq.AbstractMQ;
import com.yugao.fintech.antelope.base.model.module.mq.BaseMqPayload;
import com.yugao.fintech.framework.assistant.utils.StringUtils;

/**
 * 定义MQ消息格式
 * 业务场景： [ 支付订单超时关闭 ]
 *

 */
@Getter
@Setter
public class PayOrderCloseMQ extends AbstractMQ {
    /**
     * 延迟队列, 不能被消费监听
     */
    public static final String DELAY_QUEUE = "pay_service.close.delay.queue";

    /**
     * 进入到延迟队列的routingKey
     */
    public static final String DELAY_ROUTING_KEY = "pay_service.close.delay.routing.key";

    /**
     * 过期时间, ms单位, 上线了请改成30分钟
     */
    public static final Integer TTL = 1000 * 60 * 5;

    public PayOrderCloseMQ(MsgPayload msgPayload) {
        super(msgPayload);
    }

    /**
     * 定义Msg消息载体
     */
    @Data
    @EqualsAndHashCode(callSuper = true)
    @AllArgsConstructor
    public static class MsgPayload extends BaseMqPayload {
        /**
         * 支付订单号
         */
        private String payOrderNo;
    }


    /**
     * 构造MQModel , 一般用于发送MQ时
     */
    public static PayOrderCloseMQ build(String payOrderNo) {
        return new PayOrderCloseMQ(new MsgPayload(payOrderNo));
    }

    /**
     * 解析MQ消息， 一般用于接收MQ消息时
     */
    public static MsgPayload parse(String msg) {
        if (StringUtils.isEmpty(msg)) {
            return new MsgPayload("-1");
        }
        return JSON.parseObject(msg, MsgPayload.class);
    }
}
